package com.example.application1.Adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.application1.Entity.videoFind.视频DTO;
import com.example.application1.R;

import java.util.List;

import cn.jzvd.JzvdStd;

public class videoAdapter extends RecyclerView.Adapter<videoAdapter.videoHolder> {

    private Context context;
    private List<视频DTO> result;

    public videoAdapter(Context context, List<视频DTO> result) {
        this.context=context;
        this.result=result;
    }

    @NonNull
    @Override
    public videoHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new videoHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.video_item,parent,false));
    }

    @Override
    public void onBindViewHolder(@NonNull videoHolder holder, int position) {

        Glide.with(context)
                .load(result.get(position).getCover())
                .centerCrop()
                .placeholder(R.drawable.defaultbg)
                .into(holder.item_videoJz.posterImageView);

        Glide.with(context)
                .load(result.get(position).getVideoTopic().getTopic_icons())
                .centerCrop()
                .placeholder(R.drawable.defaultbg)
                .into(holder.item_videoImage);
        holder.item_videoJz.setUp(result.get(position).getMp4_url(),result.get(position).getTitle(),JzvdStd.SCREEN_NORMAL);
        holder.item_videoText3.setText(result.get(position).getPtime());
    }

    @Override
    public int getItemCount() {
        return result==null?0:result.size();
    }

    public  void refresh(List<视频DTO> result){
//      对适配器刷新
        this.result=result;
        notifyDataSetChanged();
        Log.d("lcj","notifyDataSetChanged");
    }

    public class videoHolder extends RecyclerView.ViewHolder{
        private JzvdStd item_videoJz;
        private ImageView item_videoImage;
        private TextView item_videoText3;
        public videoHolder(@NonNull View itemView) {
            super(itemView);
            item_videoJz= itemView.findViewById(R.id.item_videoJz);
            item_videoImage=itemView.findViewById(R.id.item_videoImage);
            item_videoText3=itemView.findViewById(R.id.item_videoText3);
        }
    }

}
